<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Approve extends CI_Controller 
	{
		 
		
		public function approveFlow(){
			
		//	echo "aaaaaaaaaaaaa";
			/////////////////////////////////////////
			///  for send mail sms to next user
			// get next flow and get next sms
			 $myID = $this->input->post("workflow_id");
			 $instance_id = $this->input->post("instance_id");
			 $this->workflow_model->completeInstance($instance_id,$myID);
			 $this->workflow_model->checkNextStep($myID ); // 1 masterreel
			 
				
			// หา Profile
				
			$inData=array( "mail_to" =>"ko@localhost",
					"email_title" =>"You have 1 job in mailbox(Masterreel)",
					"email_message" =>"<a href='http://127.0.0.1/work/project2012-3/index.php/login/index2/1/".
					$myID."'>Work </a>",
						
					"mobile"=>"0818666851"
			);
			$this->workflow_model->sendEmail($inData) ;
			// $this->workflow_model->sendSMS($inData);
			echo "NC";
				
			///// end send email sms
			
		}
		
		
		public function approveFlowPass(){
			//$myID = $this->input->post("flow_id");
			//	echo "aaaaaaaaaaaaa";
			/////////////////////////////////////////
			///  for send mail sms to next user
			// get next flow and get next sms
		     $myID = $this->input->post("workflow_id");
			 $instance_id = $this->input->post("instance_id");
			 $this->workflow_model->completeInstance($instance_id,$myID);
			 $this->workflow_model->completeFlow( $myID);
			//$this->workflow_model->checkNextStep($myID ); // 1 masterreel
		
			// หา Profile
		
			$inData=array( "mail_to" =>"ko@localhost",
					"email_title" =>"You have 1 job in mailbox(Masterreel)",
					"email_message" =>"<a href='http://127.0.0.1/work/project2012-3/index.php/login/index2/1/".
					$myID."'>Work </a>",
		
					"mobile"=>"0818666851"
			);
			$this->workflow_model->sendEmail($inData) ;
			// $this->workflow_model->sendSMS($inData);
			echo "PASS";
		
			///// end send email sms
				
		}
		public function detail_masterreel($t_id)
		{
			$t_id = $this->uri->segment(3);
			$data["instance_id"] = $this->uri->segment(4);
			$data["workflow_id"] = $this->uri->segment(3);
		    
			$data['rs1']=$this->masterreel_model->detail_masterreel1($t_id);
			$data['rs2']=$this->masterreel_model->detail_masterreel2($t_id);
			$data['instance_flow']	=$this->workflow_model->getWorkflowInstance($t_id); 
			$this->load->view('template/template');
			$this->load->view("approve/MasterReel",$data);
			$this->load->view('template/footer');
		}
		
		public function control(){
			//echo 1;
			$formId= $this->uri->segment(3);
			$tran_id = $this->uri->segment(4);
			//$formId=$this->input->get("form");
			//$tran_id=$this->input->get("id");
			//redirect(base_url()."index.php/login2/$formId/$tran_id ", 'location', 301);
			// echo $formId." ".$tran_id;
			 switch($formId){
				case	'1' : $this->detail_masterreel($tran_id);break;  // mester reel form
				case	'2' : $this->detail_masterreel($tran_id);break;	 // cut size
				case	'3' : $this->detail_masterreel($tran_id);break;
				case	'4' : $this->detail_masterreel($tran_id);break;
			}
			 
		}
		
		public function workflow(){
			$formId= $this->uri->segment(3);
			$tran_id = $this->uri->segment(4);
			redirect(base_url()."index.php/login/index2/$formId/$tran_id ", 'location', 301);
		 
		}
	}
